<?php
namespace app\home\controller;

use \app\common\controller\Homebase;
use \thans\Ret;
use \think\Db;
use \think\Loader;
use \think\Session;

class Index extends Basic
{
    public function main()
    {
        return $this->fetch();
    }
    //日常维护
    public function system()
    {
        $action = input('action');
        switch ($action) {
            case 'trace':
                if (config('app_trace') == true) {
                    $msg = '关闭Trace';
                    $res = sys_config_setbykey('app_trace', false);
                } else {
                    $msg = '打开Trace';
                    $res = sys_config_setbykey('app_trace', true);
                }

                break;
            case 'debug':
                if (config('app_debug') == true) {
                    $msg = '关闭调试';
                    $arr = array('app_debug' => false);
                    $res = sys_config_setbyarr($arr);
                } else {
                    $msg = '打开调试';
                    $arr = array('app_debug' => true);
                    $res = sys_config_setbyarr($arr);
                }
                break;
            case 'clear_log':
                remove_dir(LOG_PATH);
                $res = true;
                $msg = '清除日志';

                break;
            case 'clear_cache':
                remove_dir(RUNTIME_PATH);
                $res = true;
                $msg = '清除缓存';
                break;
            default:

                break;
        }
        if ($res) {
            return $this->ret->setCode(0)->setMsg($msg . '成功')->toJson();
        } else {
            return $this->ret->setCode(1)->setMsg($msg . '失败')->toJson();
        }

    }
}
